package blt.app_core.api.purse;


import java.util.List;

import blt.app_core.api.base.bean.State;
import blt.app_core.api.base.callback.ComBack;
import blt.app_core.api.base.callback.StateCallback;
import blt.app_core.api.impl.BaseImpl;
import blt.app_core.api.journey.bean.AppealInfo;
import blt.app_core.api.purse.bean.ChargeVo;
import blt.app_core.api.purse.bean.CouponVo;
import blt.app_core.api.purse.bean.PayVo;
import blt.app_core.api.purse.bean.PurseVo;
import blt.app_core.api.purse.bean.VoucherVo;
import blt.app_core.log.Logger;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by xgp on 2017/6/21.
 */

public class PayImpl extends BaseImpl<PayService> implements PayApi {

    @Override
    public void getPurseInfo() {
        builderLoginRequest();
        mService.getPurseInfo().enqueue(new StateCallback<PurseVo>() {

            @Override
            protected void onSuccess(PurseVo data) {
                notifyClients(PayApi.class, PayApi.onPurseInfo, data);
            }
        });

    }

    @Override
    public void getVoucherList() {
        mService.getVoucherList().enqueue(new ComBack<ChargeVo>() {
            @Override
            protected void onSuccess(List<ChargeVo> data) {
                notifyClients(PayApi.class, PayApi.onCharge, data);
            }
        });
    }

    @Override
    public void createOrder(String payChannel, int amt, String remark) {
        mService.createOrder(payChannel, amt, remark).enqueue(new StateCallback<PayVo>() {
            @Override
            protected void onSuccess(PayVo data) {
                notifyClients(PayApi.class,PayApi.onCreateOrder,data);
            }
        });

    }

    @Override
    public void getVoucherDetail() {
//        mService.getChargeDetail().enqueue(new Callback<OAuth>() {
//            @Override
//            public void onResponse(Call<OAuth> call, Response<OAuth> response) {
//                Logger.d("getVoucherDetail");
//            }
//
//            @Override
//            public void onFailure(Call<OAuth> call, Throwable t) {
//
//            }
//        });

        mService.getChargeDetail().enqueue(new ComBack<VoucherVo>() {
            @Override
            protected void onSuccess(List<VoucherVo> data) {
                Logger.d("getVoucherDetail");
                notifyClients(PayApi.class, PayApi.onChargeList, data);
            }
        });

    }

    @Override
    public void getCouponList(int page, int size) {
        mService.getCouponList(page, size).enqueue(new ComBack<CouponVo>() {
            @Override
            protected void onSuccess(List<CouponVo> data) {
                notifyClients(PayApi.class, PayApi.onCouponList, data);
            }
        });

    }

    @Override
    public void convert(String couponTicket) {
        mService.convertTick(couponTicket).enqueue(new Callback<State>() {
            @Override
            public void onResponse(Call<State> call, Response<State> response) {
                notifyClients(PayApi.class, PayApi.onConvert);
            }

            @Override
            public void onFailure(Call<State> call, Throwable t) {

            }
        });
    }

    @Override
    public void getRedInfo() {
         mService.getRedInfo().enqueue(new ComBack<AppealInfo>() {
             @Override
             protected void onSuccess(List<AppealInfo> data) {
                 notifyClients(PayApi.class,PayApi.onRedInfo,data);
             }
         });

    }

    @Override
    public void extractMoney(final String amount) {
        mService.extractMoney(amount).enqueue(new Callback<State>() {
            @Override
            public void onResponse(Call<State> call, Response<State> response) {
                notifyClients(PayApi.class,PayApi.onExtract,amount);
            }

            @Override
            public void onFailure(Call<State> call, Throwable t) {

            }
        });
    }

}
